//-----------------------------------------------------------------------------
#include "ht32.h"
#include "GPIO.h"
#include "SysTick.h"
#include "USART0.h"
#include "USART1.h"
#include "GPTM0.h"
#include "GPTM1.h"
#include "MCTM0.h"
#include "cell.h"
#include "delay.h"
//-----------------------------------------------------------------------------
int main(void)
{
  GPIO_Configuration();
  SysTick_Configuration();
  USART0_Configuration();
  USART1_Configuration();
	delay_ms(HT_NOW_CHAH*2500);
  GPTM0_Configuration();
  GPTM1_Configuration();
  MCTM0_Configuration();
	GPTM0_SetFrequency(50);
	GPTM1_SetFrequency(50);
	MCTM0_SetFrequency(50);
  init_cell_fun();

  while (1)
  {
//    get_cell_inf();
	set_cell_inf(&cell_1_inf);
	delay_ms(200);
	set_cell_inf(&cell_2_inf);
	delay_ms(200);
//	  	 for(int i = 0 ; i <100;i++){
//		 delay_ms(8);
//	  	MCTM0_CH3_SetOnduty(i);
//	  }
//	  
//	 for(int i = 100 ; i >=0;i--){
//		 delay_ms(8);
//	  	MCTM0_CH3_SetOnduty(i);
//	  }
	  
	  GPIO_WriteOutBits(OUT_PA0_GPIO_PORT,OUT_PA0_GPIO_PIN,RESET);
	  delay_ms(100);
	  GPIO_WriteOutBits(OUT_PA0_GPIO_PORT,OUT_PA0_GPIO_PIN,SET);
	  delay_ms(100);
	  
//	  	cell_1_inf.set_pin(CELL1_TIM,TM_CH_0,cell_1_inf.pin_pwm_d.pin1_pwm);
//		cell_1_inf.set_pin(CELL1_TIM,TM_CH_1,cell_1_inf.pin_pwm_d.pin2_pwm);
//		cell_1_inf.set_pin(CELL1_TIM,TM_CH_2,cell_1_inf.pin_pwm_d.pin3_pwm);
//		delay_ms(50);
//		cell_1_inf.set_pin(CELL1_TIM,TM_CH_3,cell_1_inf.pin_pwm_d.pin4_pwm);
//		cell_1_inf.set_pin(CELL1_2_TIM,TM_CH_0,cell_1_inf.pin_pwm_d.pin5_pwm);
//		cell_1_inf.set_pin(CELL1_2_TIM,TM_CH_1,cell_1_inf.pin_pwm_d.pin6_pwm);
//	delay_ms(50);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_0,cell_2_inf.pin_pwm_d.pin1_pwm);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_1,cell_2_inf.pin_pwm_d.pin2_pwm);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_2,cell_2_inf.pin_pwm_d.pin3_pwm);
//		delay_ms(50);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_3,cell_2_inf.pin_pwm_d.pin4_pwm);
//		cell_2_inf.set_pin(CELL1_2_TIM,TM_CH_2,cell_2_inf.pin_pwm_d.pin5_pwm);
//		cell_2_inf.set_pin(CELL1_2_TIM,TM_CH_3,cell_2_inf.pin_pwm_d.pin6_pwm);
//	delay_ms(50);
//	
//		cell_1_inf.set_pin(CELL1_TIM,TM_CH_0,cell_1_inf.pin_pwm_u.pin1_pwm);
//		cell_1_inf.set_pin(CELL1_TIM,TM_CH_1,cell_1_inf.pin_pwm_u.pin2_pwm);
//		cell_1_inf.set_pin(CELL1_TIM,TM_CH_2,cell_1_inf.pin_pwm_u.pin3_pwm);
//		delay_ms(50);
//		cell_1_inf.set_pin(CELL1_TIM,TM_CH_3,cell_1_inf.pin_pwm_u.pin4_pwm);
//		cell_1_inf.set_pin(CELL1_2_TIM,TM_CH_0,cell_1_inf.pin_pwm_u.pin5_pwm);
//		cell_1_inf.set_pin(CELL1_2_TIM,TM_CH_1,cell_1_inf.pin_pwm_u.pin6_pwm);
//	delay_ms(50);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_0,cell_2_inf.pin_pwm_u.pin1_pwm);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_1,cell_2_inf.pin_pwm_u.pin2_pwm);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_2,cell_2_inf.pin_pwm_u.pin3_pwm);
//		delay_ms(50);
//		cell_2_inf.set_pin(CELL2_TIM,TM_CH_3,cell_2_inf.pin_pwm_u.pin4_pwm);
//		cell_2_inf.set_pin(CELL1_2_TIM,TM_CH_2,cell_2_inf.pin_pwm_u.pin5_pwm);
//		cell_2_inf.set_pin(CELL1_2_TIM,TM_CH_3,cell_2_inf.pin_pwm_u.pin6_pwm);
//	delay_ms(300); 	
USART0_test();
delay_ms(100);
 }


}
